﻿using System;
using System.Data;
using System.Data.SqlClient;

using Dtl;

namespace Dal
{
    public class VisitDao
    {

        public static DataSet getVisitReport(string distributor, DateTime startDate, DateTime endDate, string ambient)
        {
            string connection = Credentials.getCredentias(ambient);
            if (connection == null)
            {
                return null;
            }

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = new SqlConnection(connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.CommandText = "dbo.dms_Report_ImportVisit";
            cmd.Parameters.AddWithValue("@idDistributor", distributor);
            cmd.Parameters.AddWithValue("@StartDate", startDate);
            cmd.Parameters.AddWithValue("@EndDate", endDate);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dtVisit = new DataTable("Visitdt");

            try
            {
                cmd.Connection.Open();
                da.Fill(dtVisit);
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                Credentials.writeLogFile("getVisitReport: " + ex.Message);
                return null;
            }
            DataSet ds = new DataSet("Visitds");
            ds.Tables.Add(dtVisit);           

            return ds;
        }
    }
    }
